package com.tnovoselec.server.gdjejefrka.util;

import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.tnovoselec.server.gdjejefrka.beans.Location;

public class Utils {

	public static boolean insertRowInLocations(Location location) {

		boolean flag = false;
		try {
			if (true) {
				location.insert();
				flag = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flag;
	}
	
	public static Document getReports(Location location){
		Document doc = null;
		List<Location> locations = null;
		try {
			doc = XMLUtil.getEmptyDoc();
			locations = Location.getReports(location);
			Element root = XMLUtil.createElement(doc, "reports", null);
			for (Location loc : locations){
				Element report = XMLUtil.createElement(doc, "report", root);
				XMLUtil.createElement(doc, "lat", ""+loc.getLat(), report);
				XMLUtil.createElement(doc, "lng", ""+loc.getLng(), report);
				XMLUtil.createElement(doc, "type", ""+loc.getType(), report);
				XMLUtil.createElement(doc, "timestamp", ""+loc.getTimestamp(), report);
				root.appendChild(report);
			}
			doc.appendChild(root);
			doc.normalize();
		}catch (Exception e) {
			// TODO: handle exception
		}
		
		
		return doc;
		
	}

}
